#!/bin/sh

DEFAULT_JAR_NAME=GW.jar

SERVER=$(cd `dirname $0`; pwd)
cd $SERVER

P=$1

R_JAR="$SERVER/$DEFAULT_JAR_NAME"

if [ $# -eq 0 ] ; then
    echo "Usage: {start|stop|restart|fstop}"
    echo "Abc.jar -f xxxparams"
else
    if [ "${P##*.}"x = "jar"x ] ; then
        nohup java -jar "$SERVER/$*" 2>&1 | /usr/sbin/cronolog ./logs/nohup_%Y%m%d.log &
        echo $[$!-1] > $SERVER/server.pid
    else
        case "$P" in
            start)
                 nohup java -jar $R_JAR 2>&1 | /usr/sbin/cronolog ./logs/nohup_%Y%m%d.log &
                 echo $[$!-1] > $SERVER/server.pid
                 ;;

            stop)
                kill  `cat $SERVER/server.pid`
                rm -rf $SERVER/server.pid
                ;;

            restart)
                $P stop
                sleep 1
                $P start
                ;;

            fstop)
                kill -9 `cat $SERVER/server.pid`
                rm -rf $SERVER/server.pid
                ;;

            *)
                echo "Usage: {start|stop|restart|fstop}"
                echo "Abc.jar -f xxxparams"
                ;;
            esac
    fi;
fi;
exit 0